﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NorthWin_Test.Dao;
using System.Data;
using System.Data.SqlClient;
namespace NorthWin_Test.Dao
{
    public class CategoryDao:BaseDao
    {
        public DataTable GetAllCategory()
        {
            SqlCommand command = new SqlCommand("select * from categories where categoryID=1");
            command.CommandType = CommandType.Text;
            return GetData(command);
        }
        //public int AddCategory(
        //    int categoryID,
        //    string categoryName,
        //    string description
        //    )
        //{
        //    SqlCommand command = new SqlCommand("AddCategory",Conn);
        //    command.CommandType = CommandType.StoredProcedure;
        //    command.Parameters.Add(new SqlParameter("@CategoryID",categoryID));
        //    command.Parameters.Add(new SqlParameter("@CategoryName", categoryName));
        //    command.Parameters.Add(new SqlParameter("@Description", description));
        //    command.Connection = Conn;
        //    try
        //    {
        //        Conn.Open();
        //        int result = int.Parse(command.ExecuteScalar().ToString());
        //        return result;
        //    }
        //    catch (Exception e){
        //        return 0;
        //    }
        //    finally
        //    {
        //        Conn.Close();
        //    }

        //}

        public int AddCategory(
            int categoryID,
            string categoryName,
            string description
            )
        {
            Conn.Open();
            SqlCommand command = new SqlCommand("AddCategory", Conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@CategoryID", SqlDbType.Int).Value = categoryID;
            command.Parameters.Add("@CategoryName", SqlDbType.NVarChar).Value = categoryName;
            command.Parameters.Add("@Description", SqlDbType.Text).Value = description;
            
            int result = command.ExecuteNonQuery();
            

            Conn.Close();
            return result;

        }
    }
}
